package com.wowoai.user.entity;

import com.wowoai.common.CommonConstant;
import com.wowoai.common.basemodule.BaseEntity;
import com.wowoai.user.enums.RoleEnum;
import com.wowoai.user.enums.UserStatusEnum;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 用户实体
 */
@Getter
@Setter
@Table(name = "users")
@Entity
public class UserEntity extends BaseEntity {

    /**
     * 电话号码
     */
    @Column(name = "phone_number")
    private String phoneNumber;

    /**
     * 用户昵称
     */
    @Column(name = "nick_name")
    private String nickName;

    /**
     * 注册时间
     */
    @Column(name = "register_date")
    private Long registerDate;

    /**
     * 最近登录时间
     */
    private Long lastLoginTime;

    /**
     * 积分登录提示标志，每天第一次登录提示送的积分，默认1，需要提示，0-不需要提示
     */
    private Boolean scoreTagFlag;

    /**
     * 性别
     */
    @Column(name = "gender")
    private Short gender;

    /**
     * 账号状态 1-正常 -1拉黑
     */
    @Column(name = "status")
    private Integer status;

    /**
     * 头像url
     */
    @Column(name = "avatar")
    private String avatar;

    /**
     * 角色
     */
    @Column(name = "role")
    private String role;

    /**
     * 积分
     */
    @Column(name = "score")
    private Integer score;

    /**
     *永久积分
     */
    @Column(name = "permanentScore")
    private Integer permanentScore;

    /**
     * 当天看广告次数
     */
    @Column(name = "adCount")
    private Integer adCount;

    public static UserEntity create(Long id){
        UserEntity userEntity = new UserEntity();
        userEntity.setId(id);
        userEntity.setCreatorId(id);
        userEntity.setDeleted(Boolean.FALSE);
        userEntity.setRole(RoleEnum.USER.getCode());
        userEntity.setScoreTagFlag(Boolean.TRUE);
        userEntity.setAvatar(CommonConstant.DEFAULT_AVATAR);//默认头像
        userEntity.setCreateTime(System.currentTimeMillis());
        userEntity.setRegisterDate(System.currentTimeMillis());
        userEntity.setScore(CommonConstant.defaultScore);//默认10积分
        userEntity.setPermanentScore(0);//永久积分默认0
        userEntity.setAdCount(0);
        userEntity.setStatus(UserStatusEnum.NORMALITY.getCode());//默认正常
        userEntity.setNickName("用户" + String.valueOf(id).substring(13));//默认昵称
        return userEntity;
    }
}
